﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;
using System.Collections;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToValueNullableTestFixture
    {
        public class SingleStructure<T>
        {
            public T Value { get; set; }
        }

        [Test]
        public void NullableBoolToNullablelBoolTest()
        {
            var sourceOne = new
            {
                Value = (bool?)null,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<bool?> singleStructure = ObjectToValue.Copy<SingleStructure<bool?>>(sources);

            // make sure the field was set
            Assert.IsNull(singleStructure.Value);
        }

        [Test]
        public void BoolTrueToNullableBoolTest()
        {
            var sourceOne = new
            {
                Value = true,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<bool?> singleStructure = ObjectToValue.Copy<SingleStructure<bool?>>(sources);

            // make sure the field was set
            Assert.IsTrue(singleStructure.Value.Value);
        }

        [Test]
        public void BoolFalseToNullableBoolTest()
        {
            var sourceOne = new
            {
                Value = false,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<bool?> singleStructure = ObjectToValue.Copy<SingleStructure<bool?>>(sources);

            // make sure the field was set
            Assert.IsFalse(singleStructure.Value.Value);
        }

        [Test]
        public void ShortToNullableShortTest()
        {
            var sourceOne = new
            {
                Value = (short)7,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<short?> singleStructure = ObjectToValue.Copy<SingleStructure<short?>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void ShortToNullableLongTest()
        {
            var sourceOne = new
            {
                Value = (short)7,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<long?> singleStructure = ObjectToValue.Copy<SingleStructure<long?>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void LongToNullableShortTest()
        {
            var sourceOne = new
            {
                Value = (long)7,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<short?> singleStructure = ObjectToValue.Copy<SingleStructure<short?>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void DateTimeToNullableDateTimeTest()
        {
            var sourceOne = new
            {
                Value = DateTime.Today
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<DateTime?> singleStructure = ObjectToValue.Copy<SingleStructure<DateTime?>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void NullableDateTimeToNullableDateTimeTest()
        {
            var sourceOne = new
            {
                Value = (DateTime?)DateTime.Today
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<DateTime?> singleStructure = ObjectToValue.Copy<SingleStructure<DateTime?>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void NullableDateTimeToDateTimeTest()
        {
            var sourceOne = new
            {
                Value = (DateTime?)DateTime.Today
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<DateTime> singleStructure = ObjectToValue.Copy<SingleStructure<DateTime>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void NullableLongToNullableShortTest()
        {
            var sourceOne = new
            {
                Value = (long?)7,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<short?> singleStructure = ObjectToValue.Copy<SingleStructure<short?>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void NullableLongToShortTest()
        {
            var sourceOne = new
            {
                Value = (long?)7,
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure<short> singleStructure = ObjectToValue.Copy<SingleStructure<short>>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }
    }
}
